<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>

<%@ page import="com.conversationboard.config.*" %>
<%@ page import="com.conversationboard.model.StyleSheets"%>

<%@ page pageEncoding="UTF-8"%>
<%@ page contentType="text/html;charset=UTF-8"%>

<%@ page import="com.conversationboard.view.MainMenu"%>
<%@page import="com.conversationboard.controller.confirm.Confirm"%>
<html>

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
		<title>Batch Status</title>
		<link rel="stylesheet"title="Conversation Board" type="text/css" href="<%=Configuration.getInstance().getRoot()%>/Stylesheets/<%=StyleSheets.getStyleSheetFileName(request.getCookies())%>">
	</head>

	<body>
	
		<%= MainMenu.display(request.getUserPrincipal()) %>
	
		<div class="headingblock">
			<h1>Batch Jobs</h1>
		</div>

		<div class="mainblock">


			<c:if test="${inStandby}">
				<div class="formsectionlight">
					<p><strong><span class="red">Batch scheduler Is Currently Paused.</span></strong></p>
				</div>
			</c:if>

			<c:if test="${not noJobs}">

				<h2>Currently Executing Jobs</h2>

				<div class="formsectionlight">
					<table class="table">
						
						<tr class="header">
							<td class="cell">Job Name</td>
							<td class="cell">Job Description</td>
						</tr>			
					
						<c:forEach var="job" items="${currentlyExecutingJobs}">
							<tr class="row">
								<td class="cell">${job.jobDetail.name}</td>
								<td class="cell">${job.jobDetail.description}</td>
							</tr>
						</c:forEach>
					</table>
				</div>
			</c:if>
			
			<br />
			
			<div class="formsectionlight">

				<h2>Batch Job Status</h2>

				<p><strong>Current Server Time: <span class="green">${currentServerTime}</span></strong></p>
				<p><strong>Next Batch Job Will Execute At: <span class="green">${nextTriggerToFire.nextFireTime} (in about ${nextTriggerToFirePretty} time)</span></strong></p>

				<table class="table">
					
					<tr class="header">
						<td class="cell">Trigger Name</td>
						<td class="cell">Job Name</td>
						<td class="cell">Last Fire Time</td>
						<td class="cell">Next Fire Time</td>
						<td class="cell">Run Job Now</td>
					</tr>			
				
					<c:forEach var="trigger" items="${triggers}">
						<tr class="row">
							<td class="cell">
							
								<c:choose>
									<c:when test="${trigger eq nextTriggerToFire}">
										<strong><span class="green">${trigger.name} (next to be executed in about ${nextTriggerToFirePretty})</span></strong>
									</c:when>
									<c:otherwise>
										${trigger.name}		
									</c:otherwise>
								</c:choose>
							
							</td>
							<td class="cell">${trigger.jobName}</td>
							<td class="cell">${trigger.previousFireTime}</td>
							<td class="cell">${trigger.nextFireTime}</td>
							<td class="cell">
								<form action="<%=Configuration.getInstance().getRoot()%>/Admin/AdminTriggerBatchJobControllerServlet" method="post">
									<%= Confirm.getKey(request.getUserPrincipal().getName()) %>
									<input type="hidden" name="jobName" value="${trigger.jobName}" />
									<input type="hidden" name="groupName" value="${trigger.group}" />
								 	<input type="submit" value="Execute Now" />
								</form>
							</td>
						</tr>
					</c:forEach>
				</table>
				
				</div>

				<br />

				<form class="formsection" action="<%=Configuration.getInstance().getRoot()%>/Admin/AdminBatchJobToggleControllerServlet" method="post">
					<%= Confirm.getKey(request.getUserPrincipal().getName()) %>
					<c:if test="${inStandby}">
						<p>Batch scheduler is currently paused. No batch jobs will be executed.</p>
						<input type="submit" value="      Restart Scheduler      " />
					</c:if>

					<c:if test="${not inStandby}">
						<p>Batch scheduler is currently running.</p>
						<input type="submit" value="      Pause Scheduler      " />
					</c:if>
				</form>
				
		</div>
			
		<!--<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>-->
		<!--<script type="text/javascript">_uacct = "UA-1148679-1";urchinTracker();</script>--> 
		
	</body>
	
</html>
